#include <windows.h>
#include <winsock2.h>

int i = 0x55aa55aa;

SOCKET connect_remote()
{
	//FIXME: remote address should be got from a server.
	struct sockaddr_in si;
	si.sin_family = AF_INET;
	si.sin_addr.s_addr = inet_addr("127.0.0.1");
	si.sin_port = htons(4444);
	
	SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
	if(INVALID_SOCKET == s) return INVALID_SOCKET;
	
	if(0!=connect(s, (struct sockaddr*)&si, sizeof(si)))
	{
		closesocket(s);
		return INVALID_SOCKET;
	}
	
	return s;
}

int process_events_loop(SOCKET s)
{
	return 0;
}

int main_loop()
{
	while(1)
	{
		SOCKET s = connect_remote();
		if(INVALID_SOCKET == s)
		{
			Sleep(5000);
			continue;
		}
		
		process_events_loop(s);
		shutdown(s, SD_BOTH);
		closesocket(s);
	}
}
int APIENTRY MyMain()
{
    i  = 0;
	WSADATA	wsd;
	WSAStartup(0x0202, &wsd);

	main_loop();

    return 0;
    
    
}

